package com.briup.bookstore.web.controller;

import com.briup.bookstore.common.response.Result;
import com.briup.bookstore.domain.dto.OrderPayDTO;
import com.briup.bookstore.domain.dto.OrderPaySuccessDTO;
import com.briup.bookstore.service.OrderPayService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderPayController {

    private final OrderPayService orderPayService;

    @PutMapping("/pay")
    public Result<String> pay(@RequestBody @Valid OrderPayDTO payDTO) {
        String result = orderPayService.pay(payDTO);
        return Result.success(result)
                .apply("跳转成功");
    }

    @PutMapping("/paySuccess")
    public Result<?> paySuccess(@RequestBody @Valid OrderPaySuccessDTO paySuccessDTO) {
        orderPayService.paySuccess(paySuccessDTO);
        return Result.success(null)
                .apply("支付成功");
    }
}
